package cn.fenqing.gof.observer;

import lombok.Data;
import lombok.Generated;
import lombok.Setter;
import lombok.ToString;

import java.util.ArrayList;
import java.util.List;

/**
 * @author fenqing
 */
@Data
public class User {

    private List<Observer<User>> observers = new ArrayList<>();

    public void binding(Observer<User> observer){
        observers.add(observer);
    }

    private String username;

    private String password;

    public void setUsername(String username) {
        this.username = username;
        notifyAllObservers();
    }

    public void setPassword(String password) {
        this.password = password;
        notifyAllObservers();
    }

    private void notifyAllObservers(){
        observers.forEach(Observer::update);
    }
}
